package com.waidi.clothespad.common;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.Parcelable;

/**
 * Created by ll on 2018-08-30.
 */

public class MessageToUi {
    public MessageToUi(){}
    public void send(int arg, String key, String info, Handler handler)
    {
        try {
            if(handler!=null) {

                Message msg1;
                Bundle bundle = new Bundle();
                bundle.putString(key, info);
                msg1 = handler.obtainMessage();//每发送一次都要重新获取
                msg1.arg1 = arg;
                msg1.setData(bundle);
                handler.sendMessage(msg1);
            }
        }
        catch (Exception io)
        {
            io.printStackTrace();
        }


    }

    public void sendParcelable(int arg, String key, Parcelable info, Handler handler)
    {
        try {
            if(handler!=null) {
                Message msg1;
                Bundle bundle = new Bundle();
                bundle.putParcelable(key, info);
                msg1 = handler.obtainMessage();//每发送一次都要重新获取
                msg1.arg1 = arg;
                msg1.setData(bundle);
                handler.sendMessage(msg1);
            }
        }
        catch (Exception io)
        {
            io.printStackTrace();
        }


    }


}
